#include <bits/stdc++.h>

using namespace std;

class Solution {
    int sumFromx(vector<unordered_set<int>> &edges, int source) {
        int sum = 0, level = 1;
        queue<int> q;
        unordered_set<int> s;
        q.push(source);
        s.emplace(source);
        while (!q.empty()) {
            queue<int> old(q);
            q = queue<int>();
            while (!old.empty()) {
                int u = old.front();old.pop();
                for (int v : edges[u]) {
                    if (s.count(v)) continue;
                    s.emplace(v);
                    sum += level;
                    q.push(v);
                }
            }
            level++;
        }
        return sum;
    }
public:
    vector<int> sumToAllpoints(vector<unordered_set<int>> &edges) {
        vector<int>res(edges.size(), 0);
        for (int i = 0; i < edges.size(); ++i) {
            res[i] = sumFromx(edges, i);
        }
        return res;
    }
};

int main() {
    int N;
    cin >> N;
    vector<unordered_set<int>> edges(N);
    int x, y;
    while (N--) {
        cin >> x >> y;
        edges[x].emplace(y);
        edges[y].emplace(x);
    }
    for (auto &n : Solution().sumToAllpoints(edges)) {
        cout << n << ' ';
    }
    //system("pause");
    return 0;
}
